import React from 'react'
import WNavBar from '@components/global/navBar'
import BannerModel from '@models/bannerModel'
import HomeLinkModel from '@models/homeLinkModel'
import TimeLinkModel from '@models/timeLinkModel'
import WCalendar from '@components/home/calendar'
import HomeBanner from '@components/home/banner'
import HomeLinks from '@components/home/links'
import TimeLink from '@components/home/timeLine'

interface PopInterface {
  title: string
  banners: BannerModel[],
  links: HomeLinkModel[],
  timeLines: TimeLinkModel[]
}
// @ts-ignore
const Row = ({ index, style }) => {
  return <div style={style}>Row {index}</div>
};

const HomePage = (props: PopInterface) => {

  return (
    <WNavBar title={props.title} back={false} home={false}>
      <div>
        <HomeBanner models={props.banners} />
        <WCalendar />
        <HomeLinks models={props.links} />
        <TimeLink models={props.timeLines} />
      </div>
    </WNavBar>
  )
}

HomePage.getInitialProps = async () => {
  // 获取所有的 banner 数据
  const datas = await Promise.all([
    BannerModel.loadAllModel(),
    HomeLinkModel.loadAllModel(),
    TimeLinkModel.loadAllModel()])

  return {
    title: '王亚彬的个人网站',
    layout: {
      type: 'tabBar',
      tabBar: 'home'
    },
    banners: datas[0],
    links: datas[1],
    timeLines: datas[2]
  }
}

export default HomePage
